<?php

/**
 * uniBoard ACP Access Logs
 *
 * Light and fast forum solution for web 2.0-like communities.
 *
 * @package		uniBoard
 * @author		Rafał Pitoń
 * @license		http://www.gnu.org/licenses/gpl-3.0.html
 * @since		Version 0.1
 * 
 * ------------------------------------------------------------------------
 * 
 * $Date: 2010-09-15 17:35:38 +0000 (Wed, 15 Sep 2010) $
 * $Revision: 61 $
 * $Author: rafio.xudb@gmail.com $
 */

// ------------------------------------------------------------------------

class action_logs_acp_access{
	
	/**
	 * Main class pointer
	 *
	 * @var object
	 */
	
	private $appCore		= NULL;
	
	// ------------------------------------------------------------------------

	/**
	 * Initialise Action
	 *
	 * @param object $appCore
	 */
	
	function __construct( $appCore){
		
		// Store appCore pointer
		$this -> appCore = $appCore;
		
		// Load additional lang files
		$appCore -> loadLanguageFile( 'acp_home');
		$appCore -> loadLanguageFile( 'acp_logs');
			
		// Count Access Logs
		$logs_num = $appCore -> db -> count( 'logs_admin_access');
		
		// We will Display 20 logs per page
		$paginator = new class_paginator( $appCore, $appCore -> adminLink( 'act=logs_acp_access&st=%s'), $logs_num, 20);
		
		// Draw Paginator
		$paginator_html = $paginator -> draw();
		
		// Cache output
		ob_start();
		
		// Display Paginator
		echo $paginator_html;
				
		// Open table block
		echo $appCore -> output -> openTableBlock();
		
		// Header
		echo $appCore -> output -> tableHeader( array(
			array(
				'left_float width_tiny',
				'&nbsp;'
			),
			array(
				'left_float width_long',
				$appCore -> lang['acp_home_block_admin_access_user']
			),
			array(
				'right_float width_big',
				$appCore -> lang['column_date']
			),
			array(
				'right_float width_big',
				$appCore -> lang['column_ip']
			)
		));
		
		// Select Logs from DB
		$appCore -> db -> query( 'SELECT l.log_id, l.user_id, l.user_name, l.log_ip, l.log_date, l.log_acces_state, u.user_name, g.group_prefix, g.group_suffix
		FROM ' . DB_PREFIX . 'logs_admin_access l
		LEFT JOIN ' . DB_PREFIX . 'users u ON l.user_id = u.user_id
		LEFT JOIN ' . DB_PREFIX . 'user_groups g ON u.group_id = g.group_id
		ORDER BY l.log_date DESC
		LIMIT ' . $paginator -> getPosition() . ',20');
		
		// Draw row with result
		while ( $admin_result = $appCore -> db -> fetch_array())
		{
			// Draw row
			echo $appCore -> output -> tableRow( '
				<div class="cell left_float width_tiny center">
					' . $appCore -> output -> drawImage( 'state_' . $admin_result[5], $appCore -> lang['log_admin_access_' . $admin_result[5]]) . '
				</div>
				<div class="cell left_border left_float width_long">
					<b>' . htmlspecialchars( $admin_result[1] > 0 ? $admin_result[2] : $admin_result[2]) . '</b>' . ( $admin_result[1] > 0 ? '<div class="item_description">' . $appCore -> lang['log_admin_access_as'] . ' <b>' . $admin_result[7] . htmlspecialchars( $admin_result[6]) . $admin_result[8] . '</b></div>' : '') . '
				</div>
				<div class="cell left_border right_float width_big center">
					' . $appCore -> getDate( $admin_result[4], 'short') . '
				</div>
				<div class="cell left_border right_float width_big center">
					' . $admin_result[3] . '
				</div>');		
		}
		
		// Free result
		$appCore -> db -> freeResult();
		
		// Close table block
		echo $appCore -> output -> closeTableBlock();
		
		// Display Paginator
		echo $paginator_html;
		
		// Draw output
		$appCore -> output -> draw( $appCore -> lang['acp_acp_access'], array( $appCore -> adminLink( 'act=logs_acp_access') => $appCore -> lang['acp_acp_access']), ob_get_clean());
				
	}

}